using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class EditButton : MonoBehaviour
{
    public GameObject editObject;
    public Vector2 size;
    public Text sizeTextX, sizeTextY;
    public void ChooseEditObject()
    {
        GameManager.instance.ButtonClick();
        EditManager.instance.ChangeEditObject(editObject, size);
        EditManager.instance.nowEditBorderTrans.localPosition = transform.parent.localPosition;
        EditManager.instance.nowEditBorderTrans.sizeDelta = transform.parent.GetComponent<RectTransform>().sizeDelta;
    }
    public void AddSizeX()
    {
        size.x = Mathf.Min(size.x + 1, 6);
        ChangeSize();
    }
    public void SubSizeX()
    {
        size.x = Mathf.Max(size.x - 1, 1);
        ChangeSize();
    }
    public void AddSizeY()
    {
        size.y = Mathf.Min(size.y + 1, 6);
        ChangeSize();
    }
    public void SubSizeY()
    {
        size.y = Mathf.Max(size.y - 1, 1);
        ChangeSize();
    }
    private void ChangeSize()
    {
        GameManager.instance.ButtonClick();
        sizeTextX.text = size.x.ToString();
        sizeTextY.text = size.y.ToString();
        float x, y;
        if (size.y >= size.x)
        {
            y = 50f + size.y * 25f;
            x = y * size.x / size.y;
        }
        else
        {
            x = 50f + size.x * 25f;
            y = x * size.y / size.x;
        }
        transform.parent.GetComponent<RectTransform>().sizeDelta = new Vector2 (x, y);

        if (EditManager.instance.nowEditObject != null && EditManager.instance.nowEditObject.tag == editObject.tag)
        {
            ChooseEditObject();
        }
        //Destroy(EditManager.instance.nowEditObject);
    }
}
